#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [ "${EUID}" -ne 0 ]; then
    echo -e "${ERROR} RALAT ${RESET}${TEXT} You need to run this script as root! ${RESET}"; exit 1
fi

alamat_ip=$(wget -qO- ipv4.icanhazip.com)
alamat_hos=$(cat /etc/environment | grep 'DOMAIN' | cut -d '=' -f 2 | head -n 1)
read -p "Masukkan nampa pengguna: " _namapengguna
egrep "^$_namapengguna" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
    echo -e "${ERROR} RALAT ${RESET}${TEXT} Nama pengguna sudah wujud! ${RESET}"; exit 1
fi
read -p "Masukkan kata laluan: " _katalaluan
read -p "Masukkan Tempoh aktif [Hari]: " _tempohaktif
tarikh_luput=$(date -d "$_tempohaktif days" +"%F")

useradd $_namapengguna
usermod -s /bin/false $_namapengguna
usermod -e $tarikh_luput $_namapengguna
echo -e "$_katalaluan\n$_katalaluan" | passwd $_namapengguna &>/dev/null

clear
echo
echo -e "${TEXT} ========================================================== ${RESET}"
echo -e "${TEXT} DROPBEAR & OPENVPN - BUAT AKAUN                            ${RESET}"
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo
echo -e "${YELLOW}     Alamat IP:${PLAIN} ${GREEN}$alamat_ip${PLAIN}"
echo -e "${YELLOW}   Nama domain:${PLAIN} ${GREEN}$alamat_hos${PLAIN}"
echo -e "${YELLOW} Nama pengguna:${PLAIN} ${GREEN}$_namapengguna${PLAIN}"
echo -e "${YELLOW}   Kata laluan:${PLAIN} ${GREEN}$_katalaluan${PLAIN}"
echo -e "${YELLOW}  Tempoh aktif:${PLAIN} ${GREEN}$_tempohaktif hari${PLAIN}"
echo -e "${YELLOW}  Tarikh luput:${PLAIN} ${GREEN}$tarikh_luput${PLAIN}"
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Created by Doctype, Powered by Cybertize.                  ${RESET}"
echo -e "${TEXT} Copyright 2021, Allright Reserved.                         ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo
